home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13897 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  79 lines

  1. Newsgroups: comp.lang.c
  2. Path: nntp.cadence.com!tmccoy
  3. From: tmccoy@nntp.cadence.com (Timothy McCoy)
  4. Subject: problem: sun4 and hpux char * difference
  5. Message-ID: <Dpnpn5.Lo3@Cadence.COM>
  6. Summary: C code behaves differently for sun4 and hpux
  7. Keywords: Help 
  8. Sender: news@Cadence.COM
  9. Organization: Cadence Design System, Inc.
  10. X-Newsreader: TIN [version 1.2 PL2]
  11. Date: Wed, 10 Apr 1996 17:23:28 GMT
  12.  
  13. I have a program that is made for hpux and sun4 users.
  14. The sun program fails and the hpux version does not.
  15. The problem stems from a struct definition that includes
  16. a pointer to a char.  Something like:
  17.  
  18. typedef struct record 
  19.   {            
  20.   struct rec        *first_rec ;
  21.   char              *name   ; 
  22.   } warn_record ;          
  23.  
  24. After space is allocated for the record, typically, the
  25. user will do something like this:
  26.  
  27. lrec = (struct record *)calloc((unsigned)1,sizeof(struct record));
  28. lrec->node_name = (char *) NULL;
  29.  
  30. The problem is that, on the sun only, if I try to access
  31. any of the standard string functions on this char * the 
  32. program dies with a segmentation error. e.g.;
  33.  
  34. (void) strcpy(astring, lrec->node_name ); /* fine on hp */
  35. /* Segmentation fault (core dumped) on sun4 */
  36.  
  37. I believe I understand why its dieing on the sun, as 
  38. a null (zero) address can't be read from (really) but
  39. myself and others thought that it was 'standard' to 
  40. interpret it as zero and (in this example) copy '\0'
  41. into astring, which is just what the hp does.  
  42.  
  43. Could someone shed some light on this for me?
  44.  
  45. Additionally, why, Why, WHY does the sun version of
  46. this:
  47.  
  48. printf("name='%s'\n", lrec->node_name);
  49.  
  50. yield this:
  51.  
  52. name='(null)'
  53.  
  54. and hp yields a more reasonable:
  55.  
  56. name=''
  57.  
  58. ????
  59.  
  60. Any insight will be appreciated.  Please e-mail your responses
  61. if possible.
  62.  
  63. TIA;
  64.  
  65. Tim McCoy
  66. tmccoy@cadence.com
  67.  
  68. P.S.  I resolved a small portion of the problem witha declaration:
  69.  
  70. char *CNULL = { "\0" };
  71.  
  72. and my initialization changed to:
  73.  
  74. lrec->node_name = CNULL;
  75.  
  76. (But this is only a small portion of the overriding problem.)
  77.  
  78. Thanks.
  79.